/**************************************************************
Arise Engine		EditorMaterialImport.cpp

					E-mail:	arise_engine@mail.ru

created:			09.03.2007
last changes:		10.03.2007
**************************************************************/
#include "stdafx.h"


RawMaterial::RawMaterial()
{
	m_class = CLASS_STANDART;
	m_transparency = 0;
}
RawMaterial::~RawMaterial()
{
}


void RawMaterial::Init()
{
}


void RawMaterial::Update()
{
}


void RawMaterial::TransferMaterialData(EditorMaterial &material)
{
	material.m_diffuse_map_name		= m_diffuse_map_name;
	material.m_lighting_map_name	= m_ambient_map_name;
	material.m_opacity_map_name		= m_opacity_map_name;
	material.m_transparency			= m_transparency;
}


void RawMaterial::AddSubmaterialToList(std::vector<EditorMaterial> &submaterials_list)
{
	if( IsClassMultiSubObject())
	{
		if(m_children[0].IsClassStandart())
		{
			if(submaterials_list.empty())
			{
				submaterials_list.resize(m_children.size());
			}

			for(UINT submat_id = 0; submat_id < m_children.size(); submat_id++)
			{
				m_children[submat_id].TransferMaterialData(submaterials_list[submat_id]);
			}		
		}
		else
		{
			for(UINT submat_id = 0; submat_id < m_children.size(); submat_id++)
			{
				m_children[submat_id].AddSubmaterialToList(submaterials_list);		
			}		
		}
	}
	else
	{
		if(submaterials_list.empty())
		{
			submaterials_list.resize(1);
		}
				
		TransferMaterialData(submaterials_list[0]);	
	}
}


void RawMaterial::PreProcess()
{		
	AddSubmaterialToList(m_submaterials);
}


void RawMaterial::Release()
{		
	for(	std::vector<RawMaterial>::iterator it = m_children.begin(); 
			it != m_children.end();
			it++)
	{
			(*it).Release();
	}	
	m_children.clear();

	m_submaterials.clear();
}


